<?php
namespace app\index\controller;

use think\Controller;
use app\index\service\OrderService;
use app\common\JwtToken;

class Order extends Controller
{
    private $orderService;
    private $userId;
    /**
     * 依赖注入 Service
     *
     * @param OrderService $orderService
     * @author zws
     */
    public function __construct(OrderService $orderService)
    {
        parent::__construct();
        $this->orderService = $orderService;
        $token = $this->request->param('token');
        $this->userId = JwtToken::getTokenUid($token);
    }

    /**
     * 创建工单
     * @return \think\response\Json
     * @author zws
     */
    public function add()
    {
        $input = $this->request->input;
        $input['user_id'] = $this->userId;
        $result = $this->orderService->add($input);
        return app_response(200, $result);
    }

    /**
     * 接受、取消工单
     * @return \think\response\Json
     * @author zws
     */
    public function updateStatus()
    {
        $input = $this->request->input;
        $input['user_id'] = $this->userId;
        $result = $this->orderService->updateStatus($input);
        return app_response(200, $result);
    }

    /**
     * 工单
     * @return \think\response\Json
     * @author zws
     */
    public function orderList()
    {
        $input = $this->request->input;
        $input['user_id'] = $this->userId;
        $result = $this->orderService->orderList($input);
        return app_response(200, $result);
    }

    /**
     * 上传工单数据
     * @return \think\response\Json
     * @author zws
     */
    public function uploadData()
    {
        $input = $this->request->input;
        $input['user_id'] = $this->userId;
        $input['image'] = request()->file('image');
        $result = $this->orderService->uploadData($input);
        return app_response(200, $result);
    }
}